package zcjq.d829;

import java.util.*;

public class RandomFileStream {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine().trim();
        String a = scanner.nextLine().trim();
        Map<Character, List<Integer>> map = new HashMap<>();
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (!map.containsKey(c)) {
                map.put(c, new ArrayList<>());
            }
            map.get(c).add(i);
        }
        // 循环遍历
        int slen = s.length();
        int total = 0;          // 总共浪费的个数
        int used = 0;           // 当前循环已使用的个数
        int lastPos = -1;       // 上一个字符执行s串的位置
        for (char c : a.toCharArray()) {
            int currPos = 0;
            for (int p : map.get(c)) {
                if (p > lastPos) {
                    currPos = p;
                    break;
                }
            }
            if (currPos != 0) { //可以接着用
                lastPos = currPos;
                used += 1;
            } else {  //没有可用的了
                total += slen - used;
                lastPos = -1;
                used = 0;
            }
        }
        total += lastPos - used;
        System.out.println(total);
    }
}
